package cn.bdqn.sptparent.web.mq;

import cn.bdqn.sptparent.common.util.RedisUtil;
import cn.bdqn.sptparent.domain.param.LoginParam;
import com.alibaba.fastjson.JSONObject;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class MyListener {
    @Resource
    RedisUtil redisUtil;

    /**
     * 静态Thymeleaf缓存
     * @param message
     */
    @RabbitListener(queues = RabbitConfig.SAVE_HTML)
    public void receiveHTML(String message){
        //业务逻辑  Redis  Dao  Log
        System.out.println("msg:" + message);
        // 转换为MQMessage
        MQMessage<String> mqMessage = JSONObject.parseObject(message,MQMessage.class);
        redisUtil.setHTML(mqMessage.getKey(),mqMessage.getValue(),60);
    }

    /**
     * token存储
     * @param message
     */
    @RabbitListener(queues = RabbitConfig.SAVE_TOKEN)
    public void receiveMsg(String message){
        //业务逻辑  Redis  Dao  Log
        System.out.println("msg:" + message);
        // 转换为MQMessage
        MQMessage<LoginParam> mqMessage = JSONObject.parseObject(message,MQMessage.class);
        System.out.println(mqMessage);
        System.out.println(mqMessage.getValue().getUsername());
        redisUtil.setHTML(mqMessage.getKey(),mqMessage.getValue(),60);
    }
}
